﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>统一用户授权管理系统</title>
<%@ include file="/include/header.jsp" %>
<!-- 校检规则 -->
<script src="${ctx}/js/lib/jquery-ui.custom.js" type="text/javascript"></script>
</head>
<body style="background-color: white;">
		<div style="padding: 10px;">
		<div class="b_box">
		<div class="p_bar"></div>
		<div class="ch_panel ">
	        <div class="clearfix">
	           <form id="sysRoleForm"  action="post">
	            <input type="hidden" name="CSRFToken" value="${csrfToken}" />
				<table class="c_table">
					<tr>
						<td width="120" class="t_r"><b><i class="square"></i>角色名称：</b></td>
						<td width="230"><input class="input_txt" type="text" id="roleName" name="roleName" data-validaterole="roleName" data-rule="roleName" style="width: 180px"/><i class="look"></i></td>
						<td class="t_r"><b><i class="square"></i>状&nbsp;&nbsp;态：</b></td>
						<td>
							<select  id="status" name="status" class="input_txt" style="width:150px;">
								<c:forEach items="${statusMap}" var="var">
									<option value="${var.key }">${var.value}</option>
								</c:forEach>
							</select>
					   	</td>
					</tr>
					<tr>
						<td class="t_r"><b><i class="square"></i>注&nbsp;&nbsp;释：</b></td>
						<td colspan="3"><textarea id="remark" name="remark" class="input_txt" style="height:60px;width: 508px">${sysRole.remark}</textarea></td>
					</tr>
				</table>
				</form>
			</div>
	      </div>
	</div>
	<div class="action_box m_t10 t_c"><input type="button" class="a_btn" value="保存" id="addBtn"/></div>
	</div>

	<script type="text/javascript">
		$(function(){
			
			// 验证
			seajs.use(["component/validate","component/tip"], function (validate,tip) {
				var ntip = function(){
					// 定义一个提示对象
					var t = new tip({
						content: 'hello tip',
						hasArrow: true,
						arrowOption: { dir: "left", position: { top:8 } },
						con: "body",
						hasCloseBtn: false,
						position: { my: "center", at: "center", of: "#tipcon" },
						css: { width: "120" }
					});
					return t;	
				};
			         	
				// 定义一个验证对象
				var d = new validate({
					con : "#sysRoleForm",// 验证容器
					onSubmit : "#addBtn",// 提交按钮
					eachInvalidField : function(res,field){// 验证不通过的处理
						var oldTip = field.data("tip");
						var tip;
						if(typeof oldTip == "undefined"){
							tip = ntip();
							field.data("tip",tip);
						}else{
							tip = oldTip;
						}
						tip.setContent(res.message);
						tip.setPosition({ my: "left center-15", at: "right+10 center", of: field });
						tip.show();
					},
					eachValidField : function(res,field){// 验证通过则隐藏提示
						var oldTip = field.data("tip");
						var tip;
						if(typeof oldTip == "undefined"){
						   
						}else{
							tip = oldTip;
							tip.hide();
						}
					}
				});
				// 设置拼装规则
				d.setValidateRule({ roleName : ["isBlank"] });
				// 绑定提交按钮
				d.bind("onsubmit",function(){
					var serializedForm = $("#sysRoleForm").serialize();
					$.post("${ctx}/sysRole/add", serializedForm, function (result) {
			            if ("succ" == result) {
			    			alert("操作成功");
							parent.replaceByUrl('${ctx}/sysRole/list');
							parent.layerClose(window.name);
						} else {
							alert(result);
						}
			        }, "json");
				});	
			});
		});
	</script>

</body>
</html>